-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Pass error/meta to case reducers, support non-FSAs #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Nice, I like that we're using the FSA package for consistency with other tooling.
Does this change actually cause the FSA package to pass error and meta to the reducer or is this something the user would set up manually in action creators?
Rest spread is supported in Node 8.6.0 (active LTS), so I'd recommend updating Node and not worrying about it. We could tweak babel-preset-env to compile against older versions of Node when we need to, or you can do it if you can't update Node for some reason. |
@nickmccurdy the FSA package is just used for checking if the action is a FSA. I'm passing the error and meta to the case reducer so you can use that info to transform state inside the case reducer: const addTodoSuccess = todo => ({ type: ADD_TODO, payload: todo })
const addTodoFailure = error => ({ type: ADD_TODO, payload: error, error: true })
// here we don't need to read error or meta, just payload
const addTodoReducer = (state, todo) => state.push({ ...todo, completed : false })
// here we need to read error
const notificationsReducer = (state, payload, { error }) =>
error ? state.push({ type: "danger", message: payload.message }) : state The reason is that when |
That makes sense, would you mind documenting that this convention can be optionally used in the readme? |
@nickmccurdy I've updated the |
I like your wording and the code examples, but I find the difference between the first two examples a little confusing. They both use FSAs now so maybe they should be merged since there's not much different between them. We should also stay consistent and use immer-style mutating reducers (unlike the FSA docs) because that's unrelated to how we implement reducers with or without FSAs. |
@nickmccurdy I've merged first two examples. I removed the returns, I'm not familiar with immer, so you might want to review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that's better. 😄 I'm fine with this assuming there was some basic manual testing involved, haven't tried it myself self.
Eh, I'm inclined to say we just switch back to a standard |
I'll close this PR, but please go ahead and submit one that changes |
* Add a generator for react hooks option * Add prettier, parse URLs and files from CLI Co-authored-by: kahirokunn <[email protected]>
I would like to suggest that we pass error/meta to case reducers:
It might be useful.
Also I've added support to non-FSA.
Building is now failing, I don't know how to add support for rest spread in Rollup. Alternatively I could change the code to use
omit()
: